# Parse C code for translatable strings and generate XML file

use strict;

sub Usage()
{
 print "Usage: perl transparse.pl <outfile> <file1> <file2>...\n\n";
 exit(1);
}

Usage() unless ($#ARGV > 1);

my $outname = shift @ARGV;
open(OUT,">$outname") || die "Could not write to $outname";

print OUT "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n<translation xmlns=\"http://pginstaller.projects.postgresql.org/xmlns/translation\" language=\"1033\" codepage=\"1252\">\n";
my $total = 0;

while (my $filename = shift @ARGV)
{
 open(INF,$filename) || die "Failed to open '$filename'\n";
 print "Parsing file '$filename'\n";
 while (<INF>)
 {
 	my @matches = /__\(\"([^\"]+)\"\)/g;
 	foreach my $match (@matches)
        {
 		print OUT " <string caidx=\"$total\" original=\"$match\" translation=\"\" />\n";
 		$total++;
        }
 }
 close(INF);
}

print OUT "</translation>\n";
close(OUT);
print "Done, parsed $total strings.\n";
